/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: Shentong
 * @Date: 2021-01-24 19:37:00
 * @LastEditors: Shentong
 * @LastEditTime: 2021-09-24 21:12:37
 */
import { Component } from "react";
import { Provider } from "react-redux";
import Taro from "@tarojs/taro";
import getSystemInfo from '@/utils/systemInfo'
import configStore from "./store";

// import 'taro-ui/dist/style/index.scss' // 全局引入一次即可

import "./app.scss";
import { updateWeapp } from "./utils";

// console.log(getSystemInfo())

Taro.globalSystemInfo = getSystemInfo()

const store = configStore();

Promise.prototype.finally = function(callback) {
  let P = this.constructor;
  return this.then(
    value => P.resolve(callback && callback()).then(() => value),
    reason =>
      P.resolve(callback && callback()).then(() => {
        throw reason;
      })
  );
};

class App extends Component {
  componentDidMount() {
    // 更新
    const isForce = true;
    updateWeapp(isForce);
    // 设置 保持常亮状态
    Taro.setKeepScreenOn({
      keepScreenOn: true
    });

    // 全局路由拦截
    // if (typeof wx !== "undefined") {
    //   wx.onAppRoute(function(res) {
    //     const teacherId = Taro.getStorageSync("teacherId");

    //     if (res.path !== "pages/login/index" && !teacherId) {
    //       Taro.reLaunch({
    //         url: "/pages/login/index"
    //       });
    //     }
    //   });
    // }
  }

  componentDidHide() {}

  componentDidCatchError() {}

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return <Provider store={store}>{this.props.children}</Provider>;
  }
}

export default App;
